<div class="page-container" v-cloak>
    <el-card>
        <template #header>
            <div class="breadcrumb" style=" overflow: hidden;">
                <el-breadcrumb separator="/" style=" float: left;  ">
                    <el-breadcrumb-item><a href="{:url('admin/room/index')}">包厢列表</a></el-breadcrumb-item>
                    <el-breadcrumb-item>{$title}</el-breadcrumb-item>
                </el-breadcrumb>
                <el-breadcrumb separator="/" style=" float: right;  ">
                    <el-button type="primary" @click="refresh()">刷新</el-button>
                </el-breadcrumb>
            </div>
        </template>
        <div>
            <el-form label-width="100px">
                <el-form-item label="所属门店">
                    <div>
                        <el-radio-group v-model="form.store_id">
                            <el-radio
                                    v-for="(item, index) in storeOptions"
                                    :key="item.store_id"
                                    :label="item.store_id"
                                    :disabled="item.disabled"
                            >{{item.store_name}}
                            </el-radio>
                        </el-radio-group>
                    </div>
                </el-form-item>
                <el-form-item label="包厢名称">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="包厢图片">
                    <div v-if="form.image_url" @click="show_select_image=true">
                        <el-image class="form-upload_image" :src="form.image_url"
                                  style="width:200px; height: 200px;"></el-image>
                    </div>
                    <div v-else>
                        <el-button @click="show_select_image=true" type="primary">选择图片</el-button>
                    </div>
                    <div class="form-small">
                        <small>图片大小</small>
                    </div>
                </el-form-item>

                <el-form-item label="设备标签">
                    <div>
                        <el-checkbox-group v-model="form.label">
                            <el-checkbox
                                    v-for="(item, index) in labelOptions"
                                    :key="item.room_label_id"
                                    :label="item.room_label_id"
                                    :disabled="item.disabled"
                            >{{item.name}}
                            </el-checkbox>
                        </el-checkbox-group>
                    </div>
                </el-form-item>
                <el-form-item label="套餐列表">
                    <div>
                        <el-checkbox-group v-model="form.package_id">
                            <el-checkbox
                                    v-for="(item, index) in packageOptions"
                                    :key="item.package_id"
                                    :label="item.package_id"
                                    :disabled="item.disabled"
                            >{{item.name}}/{{item.price}}元/{{item.type==0?'正常':'续费'}}
                            </el-checkbox>
                        </el-checkbox-group>
                    </div>
                </el-form-item>
                <el-form-item label="门禁版本">
                    <el-radio-group v-model="form.door_type">
                        <el-radio :label="0">版本1</el-radio>
                        <el-radio :label="1">版本2</el-radio>
                        <el-radio :label="2">版本3</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="门禁编码">
                    <el-input v-model="form.door_id"></el-input>
                </el-form-item>
                <el-form-item label="是否展示">
                    <el-radio-group v-model="form.status">
                        <el-radio :label="1">显示</el-radio>
                        <el-radio :label="0">隐藏</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="排序">
                    <el-input v-model="form.sort"></el-input>
                </el-form-item>
                <el-form-item>
                        <el-button @click="submitEvent" type="primary">
                        提交
                    </el-button>
                    <el-button @click="goBack" type="warning">
                        返回
                    </el-button>

                </el-form-item>

            </el-form>
        </div>
    </el-card>
    <select-image v-model:show="show_select_image" @confirm="selectImageConfirm"
                  @close="show_select_image=false"></select-image>
</div>
{hcmstag:include file="admin@/components/upload/select-image"}
<script>
    const App = {
        data() {
            return {
                show_select_image: false,
                form: {},
                value: [],
                image_url: '',
                labelOptions: [], // 用于存储从接口获取的选项数据
                packageOptions: [], // 用于存储从接口获取的选项数据
                storeOptions: [], // 用于存储从接口获取的选项数据
            }
        },
        mounted() {
            this.getInfo()
        },
        computed: {},
        methods: {
            handleChange(value) {
                console.log(value);
            },
            selectImageConfirm(e) {
                console.log('selectImageConfirm', e)
                this.form.image_url = e[0].file_url

                console.log(this.form.image_url)
            },
            richUpdateEvent(e) {
                console.log('richUpdateEvent', e)
            },


            /**
             * 获取编辑所需信息
             */
            getInfo() {
                let room_id = this.getUrlQuery('room_id', 0)
                console.log(room_id)
                this.httpGet("{:url('admin/room/edit')}/" + room_id, {}).then(res => {
                    if (res.status) {

                        let {labelOptions = {}, packageOptions = {}, room = {},storeOptions={}} = res.data
                        this.labelOptions = labelOptions
                        this.packageOptions = packageOptions
                        this.storeOptions = storeOptions

                        if (room.room_id) {
                            this.form = {
                                ...room,
                            }
                        }

                    }
                })
            },
            /**
             * 提交信息
             */
            submitEvent() {
                this.httpPost("{:url('admin/room/edit')}", {
                    ...this.form,
                }, true).then(res => {
                    if (res.status) {
                        if (res.data.res.role_id == 0) {
                            location.href = "{:url('admin/room/index')}"
                        }
                        this.$message.success(res.msg)
                        window.history.back();
                    }
                })
            },
            refresh() {
                location.replace(location.href);
            },
            goBack() {
                window.history.back();
            }

        }
    }
</script>

<style>
    /*默认输入框宽度*/
    .el-form-item .el-input {
        width: 500px;
    }

</style>
